/*
 * create:2016年8月8日 下午10:25:18
 * author:wangds  
 */
package com.cxkj.shop.biz.address;

import java.util.Map;

import com.cxkj.shop.form.DefaultDeliveryBuilder;
import com.cxkj.shop.form.Delivery;
import com.cxkj.shop.model.user.DefaultPostAddress;
import com.cxkj.shop.utils.BusinessUtils;
import com.cxkj.shop.utils.UserUtils;

import net.wangds.comp.business.http.AbstractBaseHttpInteractionBusiness;

/**
 * .
 * @author wangds
 *
 */
public class UpdateAsDefaultAddressBusiness  extends AbstractBaseHttpInteractionBusiness<Map<String,Object>, Delivery> {

  /*
   * @see net.wangds.comp.business.http.AbstractBaseHttpInteractionBusiness#process(java.lang.Object)
   * @author wangds 2016年4月27日 下午3:00:26.
   */
  @Override
  protected Delivery process(Map<String, Object> input) throws Exception {
    Delivery res = null;
    DefaultDeliveryBuilder<Boolean> builder = (DefaultDeliveryBuilder<Boolean>) DefaultDeliveryBuilder.<Boolean>getInstance();
    try{
      builder.init();
      
      String addId=String.valueOf(input.get("addId"));
      String openId=BusinessUtils.getOpenIdSession(BusinessUtils.getHttpSessionFromHttpBusiness(this));
      
      DefaultPostAddress address = new DefaultPostAddress();
      address.setAddId(addId);
      address.setDefaultAdd(true);
      address.setOpenId(openId);
      
      builder.setData(UserUtils.setDefaultAdd(address));
      
      builder.success();
    } catch(Exception e){
      builder.fail();
      this.getLogger().error(e.getLocalizedMessage(),e);
    } finally{
      res = builder.toDelivery();
      builder.clear();
    }
    return res;
  }


}